package com.kun.kunkunmall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 整个购物车
 */
public class Cart {
    private Integer countNum; // 购物车里面商品总数量
    private Integer countType; // 购物车里面商品种类
    private BigDecimal amount; // 购物车里面商品总价

    public Integer getCountNum() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                count ++;
            }
        }
        return count;
    }

    public BigDecimal getAmount() {
        // 计算购物总价
        BigDecimal amount = new BigDecimal("0");
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                if (item.getCheck()){
                    amount = amount.add(item.getTotalPrice());
                }
            }
        }
        // 减去优惠总价
        amount = amount.subtract(getReduce());
        return amount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    private BigDecimal reduce = new BigDecimal("0.0"); // 减免价格
    private List<CartItem> items;
}
